import React, { Suspense, Component } from "react";
import { HashRouter, Route, Switch } from "react-router-dom";
import index from "./module/index";

export default class RouteMap extends Component {
  updateHandle() {
    console.log("每次router变化之后都会触发");
  }

  render() {
    let routers = [...[index]];
    console.log(routers);
    return (
      <HashRouter onUpdate={this.updateHandle.bind(this)}>
        <Switch>
          <Suspense fallback={<h1>loading...</h1>}>
            {routers.map((module) => {
              return (
                <Route
                  key={module.path}
                  path={module.path}
                  component={() => {
                    return (
                      <module.layout>
                        {module.components.map((page) => {
                          return <Route key={page.path} {...page} />;
                        })}
                      </module.layout>
                    );
                  }}
                />
              );
            })}
          </Suspense>
        </Switch>
      </HashRouter>
    );
  }
}
